package com.lingchou.cloud.process.client.enums;

import com.lingchou.cloud.process.api.dto.constant.QueueNameConstant;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 业务key与反馈队列关系枚举
 */
public enum BusinessKeyAndMQEnum {
    /**
     * 请销假业务
     */
    LEAVE("leave", QueueNameConstant.LEAVE_EVENT_QUEUE),

    /**
     * 派车申请业务
     */
    CAR_APPLY("carApply",QueueNameConstant.CAR_APPLY_EVENT_QUEUE),

    /**
     * 家属管理申请业务
     */
    FAMILY("family",QueueNameConstant.FAMILY_EVENT_QUEUE);

    private static final Map<String,String> map = new HashMap<>(16);

    /**
     * 业务Key
     */
    private final String businessKey;

    /**
     * 队列名称
     */
    private final String queueName;

    BusinessKeyAndMQEnum(String businessKey, String queueName) {
        this.businessKey = businessKey;
        this.queueName = queueName;
    }

    static {
        Arrays.stream(BusinessKeyAndMQEnum.values())
                .forEach( businessKeyAndMQEnum -> map.put(businessKeyAndMQEnum.businessKey,businessKeyAndMQEnum.queueName));
    }

    /**
     * 根据业务Key匹配队列名
     * @param businessKey 业务Key
     * @return 队列名称
     */
    public static String matchQueue(String businessKey){
        return map.get(businessKey);
    }
}
